package com.gzw.dms.base;

import android.content.Intent;
import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
import android.support.v7.widget.Toolbar;
import android.view.View;
import android.widget.TextView;

import com.gzw.dms.MyApplication;
import com.gzw.dms.R;
import com.gzw.dms.activity.MainActivity;
import com.gzw.dms.bean.Constant;


public abstract class BaseActivity1 extends AppCompatActivity implements View.OnClickListener {
    private Toolbar toolbar;
    private TextView toolbar_tatle;
    private static final int MODE_BACK = 0;
    private static final int MODE_DRAWER = 1;
    private static final int MODE_NONE = 2;
    private long exitTime = 0;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        if (MyApplication.getFlag() == -1) {
            protectApp();
        } else {
            initViews();
            initData();
            initEvents();

        }
    }

    @Override
    public void setContentView(int layoutResId) {
        setContentView(layoutResId, 0, MODE_BACK);
    }

    public void setContentView(int layoutResId, int tatleResId) {
        setContentView(layoutResId, tatleResId, MODE_BACK);
    }

    public void setContentView(int layoutResId, int tatleResId, int mode) {
        super.setContentView(layoutResId);
        toolbar = (Toolbar) findViewById(R.id.toolbar);

        toolbar_tatle = (TextView) findViewById(R.id.toolbar_tatle);
        toolbar_tatle.setText(getResources().getText(tatleResId));
        toolbar.setTitle("");
        setSupportActionBar(toolbar);
        switch (mode) {
            case MODE_BACK:
                toolbar.setNavigationIcon(R.mipmap.jiantou_zuo);
                toolbar.setNavigationOnClickListener(this);
                break;
            case MODE_DRAWER:
                break;
            case MODE_NONE:
                break;

        }
    }

    protected abstract void initViews();

    protected abstract void initData();

    protected abstract void initEvents();

    protected void protectApp() {
        Intent intent = new Intent();
        intent.setClass(this, MainActivity.class);
        intent.putExtra(Constant.KEY_PROTECT_APP, true);
        startActivity(intent);
        finish();
    }

    @Override
    public void onClick(View v) {
        finish();
    }

}
